
import { Provide, Inject } from '@midwayjs/core';
import { BrandConfigModel } from '../entity/brand_config.method'
@Provide()
export class BrandConfigService {

  @Inject()
  BrandConfigModel: BrandConfigModel
  /**
   * 获取所有品牌列表
   */
  async getAllBrandsPage(): Promise<any> {
    const resList = await this.BrandConfigModel.getAllBrandsPage();
    return resList
  }

  /**
   * 品牌信息分页查询
   * @param {*} pageSize 
   * @param {*} pageNum 
   * @param {*} searchKey 
   */
  async getBrandsPage(params: any): Promise<any> {
    const { pageSize, pageNum, searchKey } = params;

    const total = await this.BrandConfigModel.getTotalNum(searchKey);
    const res = {
      total: total[0].num,
      lists: []
    }

    if (total[0].num) {
      const resList = await this.BrandConfigModel.getDataByPage(pageNum, pageSize, searchKey);
      res.lists = resList;
    }
    return res

  }

  /**
   * 修改品牌信息
   * @param {*} id   id
   * @param {*} brandName     品牌名称
   * @param {*} brandImg      品牌logo
   * @param {*} alarmConfig    钉钉告警群机器人配置
   */
  async updateBrands(params: any): Promise<any> {
    const { id, brandName, brandImg, alarmConfig } = params;
    await this.BrandConfigModel.updateDataById({ id, brandName, brandImg: brandImg || "", alarmConfig });
    return "修改成功"
  }

  /**
   * 新增品牌信息
   * @param {*} brandName  品牌名称
   * @param {*} brandImg   品牌logo
   * @param {*} alarmConfig    钉钉告警群机器人配置
   */
  async insertBrands(params: any): Promise<any> {
    const { brandName, brandImg, alarmConfig } = params;

    await this.BrandConfigModel.insertDataInfo({ brandName, brandImg: brandImg || "", alarmConfig });
    return "新增成功"

  }

  /**
  * 删除品牌信息
  * @param {*} id
  */
  async deleteBrands(id: any): Promise<any> {
    await this.BrandConfigModel.deleteDataById(id);
    return "删除成功"
  }

}
